<?php
if (!defined('ROOT')) {
   die("Impossible de voir ce fichier directement.");
}

class Database
{
    var $mysql_server = "";
    var $mysql_database = "";
    var $mysql_user = "";
    var $mysql_password = "";
    
    var $mysql_error = 0;
    var $mysql_handler;
    var $first_connexion = true;
    var $connected = false;
    
    function __construct($choice=NULL) {
        $this->connect($choice);
    }
    
    function   connect($choice=NULL) {

      $this->connected = false;

      if (is_array($this->mysql_server)) {
         // Round robin choice
         $i    = (isset($choice) ? $choice : mt_rand(0,count($this->mysql_server)-1));
         $host = $this->mysql_server[$i];

      } else {
         $host = $this->mysql_server;
      }

      $this->mysql_handler = @mysql_connect($host, $this->mysql_user, rawurldecode($this->mysql_password))
                   or $this->mysql_error = 1;

      if ($this->mysql_handler) { // connexion ok
         @mysql_query("SET NAMES '" . (isset($this->dbenc) ? $this->dbenc : "utf8") . "'",
                      $this->dbh);
         $select= mysql_select_db($this->mysql_database)
                  or $this->error = 1;

         if ($select) { // select ok
            $this->connected = true;
         } else { // select wrong
            $this->connected = false;
         }

      } else { // connexion wrong
         $this->connected = false;
      }
   }
    
    
    function close() {

      if ($this->mysql_handler) {
         return @mysql_close($this->mysql_handler);
      }
      return false;
   }
   
   
   
   
    

    
   
}
?>